#include <sys_head.h>

sem_t sem1, sem2;
int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

void *abc(void *p)
{
    for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); i++)
    {
        if (arr[i] % 2 == 0)
        {
            sem_wait(&sem2);
            printf("子进程:arr[%d]=%d\n", i, arr[i]);
            sem_post(&sem1);
        }
    }
}

int main(int argc, char const *argv[])
{
    pthread_t pt;
    pthread_create(&pt, NULL, abc, NULL);
    sem_init(&sem1, 0, 1);
    sem_init(&sem2, 0, 0);
    for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); i++)
    {
        if (arr[i] % 2 != 0)
        {
            sem_wait(&sem1);
            printf("父进程:arr[%d]=%d\n", i, arr[i]);
            sem_post(&sem2);
        }
    }
    void *ptest;
    pthread_join(pt,&ptest);
    return 0;
}
